package course.java.hr;

public abstract class TaxableEntity implements Comparable<TaxableEntity>
{

	private String name;
	private String taxId;

	protected TaxableEntity()
	{}
	
	public TaxableEntity(String name, String taxId)
	{
		setName(name);
		setTaxId(taxId);
	}
	
	
	public abstract float pay();
	
	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		if (name != null && name.matches("^[\\w\\s,]{4,30}$"))
			this.name = name;
		else
			throw new IllegalArgumentException("invalid name format");
	}

	public String getTaxId()
	{
		return taxId;
	}

	public void setTaxId(String taxId)
	{
		if (taxId != null &&  taxId.matches(getTaxIdRegex()))
			this.taxId = taxId;
		else
			throw new IllegalArgumentException("bad taxid");
	}
	
	protected abstract String getTaxIdRegex();

	@Override
	public boolean equals(Object obj)
	{
		if (obj instanceof TaxableEntity)
		{
			TaxableEntity other = (TaxableEntity)obj;
			return getName().equals(other.getName());
		}
		else
			return false;
	}

	@Override
	public int hashCode()
	{
		return getName().hashCode();
	}

	@Override
	public int compareTo(TaxableEntity other)
	{
		return getName().compareTo(other.getName());
	}

}













